<template>
  <div
    style="
      height: calc(100% - 70px);
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
    "
  >
    <el-card style="width: 50%">
      <h3 style="text-align: left">个人信息</h3>
      <hr />
      <div style="text-align: left; margin-left: 20px; font-size: 12px">
        <el-form ref="form" :model="form" label-width="100px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="头像">
                <el-upload
                  style="width: 50%; height: 50%"
                  action="https://jsonplaceholder.typicode.com/posts/"
                  list-type="picture-card"
                  :on-preview="handlePictureCardPreview"
                  :on-remove="handleRemove"
                >
                  <i class="el-icon-plus"></i>
                </el-upload>
                <el-dialog :visible.sync="dialogVisible">
                  <img width="100%" :src="dialogImageUrl" alt="" />
                </el-dialog>
              </el-form-item>
            </el-col>
            <el-row>
              <el-col :span="12">
                <el-form-item label="昵称">
                  <el-input v-model="form.name"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="账号">
                  <el-input v-model="form.account"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="邮箱">
                <el-input v-model="form.postbox"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份">
                <el-input v-model="form.status"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <div style="display: flex; justify-content: flex-end">
            <el-button @click="onSubmit()" type="primary">保存</el-button>
            <el-button @click="cancel()">取消</el-button>
          </div>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogImageUrl: '',
      dialogVisible: false,
      form: {
        name: '',
        account: '',
        status: '',
        postbox: ''
      }
    }
  },
  methods: {
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },

    onSubmit() {
      this.$confirm('保存个人信息设置?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch((err) => {
        this.$message({
          type: 'error',
          message: err
        })
      })
    },
    cancel() {
      ;(this.form.name = null), (this.form.account = null)
      this.form.status = null
      this.form.postbox = null
    }
  }
}
</script>

